package com.boe.csb.core.test.caller;

import com.alibaba.csb.sdk.HttpCaller;
import com.alibaba.csb.sdk.HttpCallerException;

import java.util.HashMap;
import java.util.Map;

public class JavaCaller {
	
	/**
	 * 服务调用
	 * @param httpUrl 请求接口
	 * @param reqMethod 使用get/post提交请求
	 * @param params 请求参数
	 * @return
	 */
	public static String request(String httpUrl, String reqMethod, Map<String, String> params, String version) {
		
		if(httpUrl == null || reqMethod == null || params == null){
			return null;
		}

		//String API_NAME = "你自己的api名称";
		//String ak = "你自己的ak";
		//String sk = "你自己的sk";
		String API_NAME = "dt_sql_02";
		String ak = "9f443914e0f14814ac8e073f82aae83c";
		String sk = "+YL01uT8X9kUiDxSl1Mn6Dbpc9A=";

		String result = null;
		try {
			
			if("get".equals(reqMethod)){
				result = HttpCaller.doGet(httpUrl, API_NAME, version, params, ak, sk);
			}else if("post".equals(reqMethod)){
				result = HttpCaller.doPost(httpUrl, API_NAME, version, params, ak, sk);
			}

			if (result != null) {
				// 返回结果处理, 如转换为JSON对象
			}
		} catch (HttpCallerException e) {
			// 调用异常处理
		}
		
		return result;
	}
	
	public static void main(String[] args) {
//		String httpUrl = "${httpUrl}";
//		String reqMethod = "${reqMethod}";
//		String paramStr = "${paramStr}";

		String httpUrl = "http://120.26.110.147:8086/xinghe_csb";
		String reqMethod = "get";
		Map<String, String> params = new HashMap<String, String>();
		String version = "1.0.0";

		params.put("data", "{\"action\":\"get\"}");
		
		request(httpUrl, reqMethod, params, version);
	}
}
